package com.info.zhiduoduo.repository.dto.partner;

import com.info.zhiduoduo.common.constants.partner.PartnerStudioBrokerageType;
import com.info.zhiduoduo.common.utils.NumberUtil;
import com.info.zhiduoduo.repository.dto.maker.StudioDetailDto;

import java.math.BigDecimal;
import java.math.RoundingMode;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class PartnerStudioRemitProjectExportDto {

	//序号

	private Integer row;

	private String projectName;

	private String projectDesc;

	private BigDecimal projectAmount;
	// 商业服务
	private String projectCategory;
	// 普票
	private String invoiceType;
	// 服务费
	private String invoiceContent;
	// 是
	private String authCheck;
	//姓名

	private String name;
	//银行卡号

	private String acctno;
	//身份证号

	private String idno;

	// 提现id
	private String wdid;

	/** 合伙人姓名 */
	private String partnerName;

	/** 佣金类型： 1：  2：智众包 */
	private String brokerageType;

	/** 创客费率，标准的服务费+税费 */
	private String serviceRate;

	/** 申请提现金额 */
	private BigDecimal applyAmount;

	public static PartnerStudioRemitProjectExportDto of(PartnerStudioWithdrawDto ps, StudioDetailDto maker, double serviceRate) {
		String brokerageType = ps.getBrokerageType() == 2 ? "智众包" : " ";
		String projectName = "合作佣金";
		BigDecimal projectAmount = BigDecimal.ZERO;
		if (NumberUtil.equals(ps.getBrokerageType(), PartnerStudioBrokerageType.ZHIDUODUO)) {
			//  佣金就是提现申请金额（10000）
			projectAmount = ps.getAmount();
		} else if (NumberUtil.equals(ps.getBrokerageType(), PartnerStudioBrokerageType.CROWDSOURCE)) {
			// 智众包佣金系统先按6个点倒推出发的金额10000*0.94/(1-创客费率)
			projectAmount = ps.getAmount()
					.multiply(BigDecimal.valueOf(0.94))
					.divide(BigDecimal.valueOf(1 - serviceRate), RoundingMode.DOWN);
		}

		return new PartnerStudioRemitProjectExportDto().setProjectName(projectName)
				.setProjectDesc("合作佣金")
				.setProjectAmount(projectAmount)
				.setProjectCategory("商业服务")
				.setInvoiceType("普票")
				.setInvoiceContent("服务费")
				.setAuthCheck("是")
				.setName(maker.getPayername())
				.setAcctno(maker.getAcctno())
				.setIdno(maker.getIdno())
				.setWdid(String.valueOf(ps.getId()))
				.setPartnerName(ps.getPartnerName())
				.setServiceRate(NumberUtil.formatPercent(serviceRate, 2))
				.setBrokerageType(brokerageType)
				.setApplyAmount(ps.getAmount());
	}

	public PartnerStudioRemitProjectExportDto add(PartnerStudioRemitProjectExportDto other) {
		this.projectAmount = this.projectAmount.add(other.getProjectAmount());
		this.wdid += ("," + other.wdid);
		this.applyAmount = this.applyAmount.add(other.applyAmount);
		return this;
	}
}
